
/**
 * 通知管理初始化
 */
var CdssDataLogList = {
    id: "cdssDataLogTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CdssDataLogList.initColumn = function () {
    return [
        {
            width: 30, align: "center", valign: 'middle', sortable: true, formatter:
                function (value, row, index) {
                    //获取每页显示的数量
                    var pageSize = $('#cdssDataLogTable').bootstrapTable('getOptions').pageSize;
                    //获取当前是第几页
                    var pageNumber = $('#cdssDataLogTable').bootstrapTable('getOptions').pageNumber;
                    //返回序号，注意index是从0开始的，所以要加上1
                    return pageSize * (pageNumber - 1) + index + 1;
                }
        },
        {title: '病种名称', field: 'entityName', align: 'center', width: 150, valign: 'middle', sortable: false},
        {title: '方案类型', field: 'itemType', align: 'center', width: 90, valign: 'middle', sortable: false,
            formatter: function (value, row, index) {
                if (1 == value) {
                    return "推荐评估量表";
                } else if (2 == value) {
                    return "推荐检查";
                }else if (3 == value) {
                    return "推荐检验";
                }else if (4 == value) {
                    return "推荐治疗方案";
                }else if (5 == value) {
                    return "推荐护理处置";
                }
            }
        },
        {title: '操作人', field: 'operUser', align: 'center', width: 80, valign: 'middle', sortable: false},
        {title: '更新日期', field: 'operTime', align: 'center', width: 120, valign: 'middle', sortable: false},
        {title: '操作类型', field: 'operType', align: 'center', width: 80, valign: 'middle', sortable: false,
            formatter: function (value, row, index) {
                if (1 == value) {
                    return "新增";
                } else if (2 == value) {
                    return "修改";
                }
                else if (3 == value) {
                    return "删除";
                }
            }
        },
        {title: '操作内容', field: 'operContent', align: 'center', width: 240, valign: 'middle', sortable: false}
    ];
};

/**
 * 查询病例
 */
CdssDataLogList.search = function () {
    var queryData = {};
    queryData['entityId'] = $('#QCDic').combobox('getValue');
    queryData['itemType'] = $('#recommendType').combobox('getText');
    CdssDataLogList.table.refresh({query: queryData, pageNumber: 1});
}

/**
 * 打开查看病种入组病例详情
 */
CdssDataLogList.edit = function (id,name,mrNum,dishDate,state) {
    var flag = false;
    if (id) {
        flag = true;
    } else if (SdsQcincase2.check()) {
        id = this.seItem.id;
        flag = true;
    }
    if (flag) {
        var title = "姓名:"+name+"|"+"病案号:"+mrNum+"|"+"出院日期:"+dishDate+"|"+"填报状态:"+state;
        var index = Sys.open_c(title, '/sds/sdsqcformshow?mrListId=' + id + '&checkPerm=1&reUploadFlag=1', null, function () {
            UploadList.table.refresh();
        });
        this.layerIndex = index;
    }
};

/**
 * 打开查看病例操作记录
 */
CdssDataLogList.record = function (id, mrno, name) {
    var flag = false;
    if (id) {
        flag = true;
    }
    if (flag) {
        var index = Sys.open('【填报日志】姓名：' + name + ' 病案号：' + mrno, Sys.backendPath + '/sds/sdsqcincaseoperlog/' + id, ['800px', '420px']);
        this.layerIndex = index;
    }
};


$(function () {
    //病种
    $('#QCDic').combobox({
        data: $.parseJSON($("#entityMap").val()),
        valueField: 'value',
        textField: 'text',
        defaultFilter: 6
    });
    //渲染datebox --没有渲染的话 图标左右间距不等
    $('.hisui-datebox').datebox({});
    var entityId = $("#entityId").val();
    Common_SetValue('QCDic', entityId);

    var entityType = $('#QCDic').combobox('getValue');
    var itemType = $('#recommendType').combobox('getText');
    var defaultColunms = CdssDataLogList.initColumn();
    var table = new BSTable(CdssDataLogList.id, Sys.backendPath + "/sdc/sdccdssitem/logList", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams({entityId: entityType, itemType: itemType});
    table.setShowColumns(false);
    table.setShowRefresh(false);
    table.setShowToggle(false);
    table.setPageSize(15);
    table.setSubHeight(-27);
    // table.setOnDblClickRow(UploadList.qcFormShow); //双击数据行打开表单填报

    CdssDataLogList.table = table.init();
});

function Common_SetValue() {
    var itmValue = '';

    var val = arguments[1];
    var txt = arguments[2];

    if (typeof(arguments[0]) !== 'string') return '';
    if (arguments[0] == '') return '';

    var $this = $('#'+ arguments[0]);
    if ($this.length < 1) return '';
    if (typeof val == 'undefined') val = '';
    if (typeof txt == 'undefined') txt = '';

    var className = $this.attr("class").split(' ')[0];

    if (className == 'textbox') {  //文本框
        itmValue = $this.val(val);
    }else if (className == 'hisui-numberbox') {  //数字
        itmValue = $this.val(val);
    }else if (className == 'hisui-datebox') {  //日期
        itmValue = $this.datebox('setValue',val);
    }else if (className == 'hisui-timespinner') {  //时间框
        itmValue = $this.timespinner('setValue',val);
    }else if (className == 'hisui-combobox') {  //下拉框
        if(val !="" && txt ==""){
            itmValue = $this.combobox('setValue',val);
        }else{
            itmValue = $this.combobox('setValue',txt);
        }
    }else if (className == 'hisui-switchbox') {  //开关
        itmValue = $this.switchbox('setValue',val);
    }else if (className == 'hisui-checkbox') {  // 单个复选框
        if (val == '') val = 0;
        itmValue = $this.checkbox('setValue',(val) ? true : false);
    }else if (className == 'hisui-radio') {  //单个单选框
        if (val == '') val = 0;
        itmValue = $this.radio('setValue',(val) ? true : false);
    }else if (className == 'hisui-searchbox') {  //查询框框
        itmValue = $this.searchbox('setValue',val);
    }

    return itmValue;
}
